package com.huawei.orderservice.controller;

import com.huawei.common.pojo.Result;
import com.huawei.orderservice.pojo.dto.OrderDTO;
import com.huawei.orderservice.pojo.dto.OrderUpdateDTO;
import com.huawei.orderservice.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "订单服务")
@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private OrderService orderService;



    @Operation(summary = "根据订单id查询订单-测试")
    @GetMapping("/{id}")
    public String getOrderById(@RequestHeader("Authorization") String token, @PathVariable("id") Long id) {
        System.out.println("知行了order方法 " + id);
        return "订单id";
    }


    @Operation(summary = "创建订单")
    @PostMapping("/createOrder")
    public Result createOrder(@RequestHeader("Authorization") String token, @RequestBody OrderDTO order) {
        return orderService.createOrder(order);
    }


    @Operation(summary = "修改订单信息")
    @PostMapping("/update")
    public Result updateOrder(@RequestHeader("Authorization") String token, @RequestBody OrderUpdateDTO order) {
        return orderService.updateOrder(order);
    }


    @Operation(summary = "订单结算")
    @PostMapping("/payment/{id}")
    public Result payment(@RequestHeader("Authorization") String token, @PathVariable("id") Long id) {
        return orderService.payment(id);
    }


    @Operation(summary = "取消订单")
    @PostMapping("/cancel/{id}")
    public Result cancelOrder(@RequestHeader("Authorization") String token, @PathVariable("id") Long id) {
        return orderService.cancelOrder(id);
    }
























}
